/*
 * File:   main.cpp
 * Author: Kreyl
 * Project: Armlet2South
 *
 * Created on Feb 05, 2013, 20:27
 */

#include "led.h"
#include "kl_lib_f100.h"
#include "ch.h"
#include "hal.h"


// Internal
#include "stdlib.h" // for rand
static inline void Init();
static inline void SilTask();

int main(void) {
    // ==== Init clock system ====
    Clk.SetupBusDividers(ahbDiv8, apbDiv1, apbDiv1);
    Clk.UpdateFreqValues();
    // ==== Init OS ====
    halInit();
    chSysInit();
    // ==== Init Hard & Soft ====
    Init();

    while(TRUE) {
        SilTask();
        chThdSleepMilliseconds(121);
    }
}


void SilTask() {
    if(Led.ICurrentBright.North == clMax) {
        Led.SetBrightSmoothly(chS);
    }
    if(Led.ICurrentBright.South == clMax) {
        Led.SetBrightSmoothly(chW);
    }
    if(Led.ICurrentBright.West  == clMax) {
        Led.SetBrightSmoothly(chE);
    }
    if(Led.ICurrentBright.East  == clMax) {
        Led.SetBrightSmoothly(chN);
    }
//    Uart.Printf("a");
}



void Init() {
    JtagDisable();
    Uart.Init(57600);

    Led.Init();
    Led.SetBrightSmoothly(chN);
	Uart.Printf("\r Siglstone  AHB=%u; APB1=%u; APB2=%u\r", Clk.AHBFreqHz, Clk.APB1FreqHz, Clk.APB2FreqHz);
}
